#define _CRT_SECURE_NO_WARNINGS 1

//https://leetcode.cn/problems/multiply-strings/

class Solution {
public:
    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0") return "0";

        int n = num1.size(), m = num2.size();
        int size = n + m - 1;
        vector<int> tmp(size);
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                tmp[i + j] += (num1[i] - '0') * (num2[j] - '0');
            }
        }

        string ret;
        int t = 0;
        for (int i = 0; i < size; i++)
        {
            tmp[i] += t;
            t = tmp[i] / 10;
            ret += (tmp[i] % 10) + '0';
        }
        if (t) ret += t + '0';
        reverse(ret.begin(), ret.end());
        return ret;
    }
};